package com.dingdong.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dingdong.common.pojo.EUTreeNode;
import com.dingdong.mapper.TbItemCatMapper;
import com.dingdong.pojo.TbItemCat;
import com.dingdong.pojo.TbItemCatExample;
import com.dingdong.pojo.TbItemCatExample.Criteria;
import com.dingdong.service.ItemCatService;

/**
 * 商品分类管理
 * @author think
 *
 */
@Service
public class ItemCatServiceImpl implements ItemCatService {

	@Autowired
	private TbItemCatMapper itemCatMapper;
	
	@Override
	public List<EUTreeNode> getItemCatList(long parentId) {
		TbItemCatExample example = new TbItemCatExample();
		
		Criteria criteria = example.createCriteria();
		criteria.andParentIdEqualTo(parentId);
		
		List<TbItemCat> list = itemCatMapper.selectByExample(example);
		
		List<EUTreeNode> resultList = new ArrayList<>();
		
		for (TbItemCat itemCat : list) {
			EUTreeNode treeNode = new EUTreeNode(itemCat.getId(),
					itemCat.getName(),itemCat.getIsParent()?"closed":"open"); 
			resultList.add(treeNode); 
		}
		
		return resultList;
	}

}
